package com.fuhan.controller;

import com.fuhan.common.restful.ResponseEnum;
import com.fuhan.common.restful.ResponseJSON;
import com.fuhan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: Chao
 * @description:
 * @Date: 2021/1/28 14:41
 */
@RestController
@RequestMapping("/api")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResponseJSON<Map<String, Object>> login(@RequestBody Map<String, String> map){
        String username = map.get("username");
        String password = map.get("password");
        String identify = map.get("identify");
        String code = map.get("code");
        return new ResponseJSON<>(userService.login(username, password,identify,code), ResponseEnum.LOGIN_SUCCESS);
    }

    @RequestMapping(value = "/code",method = RequestMethod.GET)
    public ResponseJSON<Map<String,String>> getCode(){
        return new ResponseJSON<>(userService.getVerificationCode(),ResponseEnum.GET_CODE);
    }
}
